<template>
  <div class="pyramid">
    <div class="legend" v-if="legend.length > 0">
      <span class="legend-span" v-for="(item, index) in legend" :key="index">
        <i :style="'color:' + tipsColor[index]" v-if="tipsColor"></i>
        <i v-else></i>
        {{ item }}
      </span>
    </div>
    <div class="pyramid-img" :class="{'empty-legend': legend.length == 0}">
      <img :src="imgSrc" v-if="imgSrc"/>
      <img :src="imgSrcArr[imgIndex]" v-else/>
      <div class="pyramid-data">
        <span class="pyramid-data-li" :class="{'more-than-one': tipsMessage.length > 1}" v-for="(item, index) in tipsMessage" :key="index">
          {{ item.beforeMessage }}:
          <i :style="'color:' + tipsColor[index]" v-if="tipsColor">
            {{ item.message }}
            {{ item.unit }}
          </i>
          <i :class="{'red': imgIndex[index] == 1, 'yellow': imgIndex[index] == 2}" v-else>
            {{ item.message }}
            {{ item.unit }}
          </i>
        </span>
      </div>
    </div>
    <p class="pyramid-title">{{ title }}</p>
  </div>
</template>

<script>
export default {
  name: 'pyramid',
  props: {
    // 头部信息
    title: {
      type: String,
      default: '',
      required: true
    },
    // 图片的Index值，0是蓝色， 1是红色， 2，是黄色
    imgIndex: {
      type: Array,
      default: () => {
        return [0]
      },
      required: true
    },
    // 提示信息
    tipsMessage: {
      type: Array,
      default: () => {
        return [{
          beforeMessage: '',
          message: '',
          unit: ''
        }]
      }
    },
    // 引用图片的路径，当这个参数存在的时候，
    imgSrc: {
      type: String
    },
    // 当使用imgSrc的时候，需要传提示字的颜色用于显示
    tipsColor: {
      type: Array
    },
    legend: {
      type: Array,
      default: () => []
    }
  },
  components: {
  },
  data () {
    return {
      imgSrcArr: [require('./../../assets/images/module/pyramid-blue.png'),
        require('./../../assets/images/module/pyramid-red.png'),
        require('./../../assets/images/module/pyramid-yellow.png'),
        require('./../../assets/images/module/pyramids.png'),
        require('./../../assets/images/module/pyramids-third.png')
      ]
    }
  },
  methods: {
  },
  mounted () {
  },
  watch: {
  }
}
</script>

<style lang="scss" scoped="scoped">
  .pyramid{
    width: 100%;
    height: 100%;
    position: relative;
    .legend{
      width: 100%;
      margin-top:10px;
      font-size: 12px;
      color: #fff;
      overflow: hidden;
      .legend-span{
        display: block;
        float: left;
        margin: 0 0 0 10px;
        i{
          display: inline-block;
          width: 8px;
          height: 8px;
          margin-right: 3px;
          border-radius: 100%;
        }
        &:first-of-type{
          margin: 0;
          i{
            background: #2e92cb;
          }
        }
        &:nth-of-type(2){
          i{
            background: #b60d81;
          }
        }
        &:nth-of-type(3){
          i{
            cbackgroundolor: #d38f44;
          }
        }
      }
    }
    .pyramid-img {
      width: 40%;
      display: block;
      float: left;
      margin: 10px 0 5px 30%;
      position: relative;
      &.empty-legend{
        /*margin: 18% 0 5px 20%;*/
        margin: 10px 0 5px 30%;
      }
      &:hover{
        .pyramid-data{
          display: block;
        }
      }
      img {
        width: 100%;
      }
      .pyramid-data {
        position: absolute;
        right: 0;
        top: 30%;
        z-index: 15;
        border-radius: 4px;
        background: rgba(7, 23, 62, 0.8);
        border: 1px solid #1072e2;
        padding: 14px;
        display: none;
        .pyramid-data-li {
          display: block;
          width: 100%;
          text-align: center;
          font-size: 12px;
          line-height: 16px;
          color: #fff;
          white-space: nowrap;
          i {
            color: #2e92cb;
            &.red {
              color: #b60d81;
            }
            &.yellow {
              color: #d38f44;
            }
          }
          &.more-than-one:first-of-type{
            i{
              color:#2e92cb;
            }
          }
          &.more-than-one:nth-of-type(2){
            i{
              color:#b60d81;
            }
          }
          &.more-than-one:nth-of-type(3){
            i{
              color:#d38f44;
            }
          }
        }
      }
    }
    .pyramid-title{
      width: 100%;
      float: left;
      height:20px;
      line-height: 20px;
      margin-left:0;
      display: block;
      text-align: center;
      box-sizing: border-box;
      color: #fff;
      font-size: 12px;
    }
  }
</style>
